package org.zcl.event;

import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;
import org.springframework.stereotype.Component;

/**
 *
 * @author: ZCL
 * @since: 2021/10/18 14:09
 */
@Component
public class CustomEventPublisher implements ApplicationEventPublisherAware {

    private ApplicationEventPublisher publisher;

    @Override
    public void setApplicationEventPublisher(ApplicationEventPublisher publisher) {
        this.publisher = publisher;
    }

    public void publish(){
        CustomEvent customEvent = new CustomEvent(this);
        System.out.println("事件已触发！");
        publisher.publishEvent(customEvent);
    }
}
